/*
	作者：杨金良
	*/
var	urlHead = "/International";
//variables变量
var setMajor2Url = urlHead + "/adminCourseManage/setMajor2"; //获取课表
var delectCourseUrl = urlHead + "/adminCourseManage/deleteCourse";//删除课程
var showUpdateCourseUrl = urlHead + "/adminCourseManage/showUpdateCourse";//获取单个课程的教师和学生信息
var updateCourseUrl = urlHead + "/adminCourseManage/updateCourse";
var newCourseUrl = urlHead + "/adminCourseManage/setCourse";// 新增课程
var addCourseUrl = urlHead + "/adminCourseManage/addCourse";// 新增课程

function O(_id){
	return document.getElementById(_id);
}
//改变select选中状态
function setSelectChecked(selectId, checkValue){  
    var select = O(selectId);  
    for(var i=0; i<select.options.length; i++){  
        if(select.options[i].innerHTML == checkValue){  
            select.options[i].selected = true;  
            break;  
        }  
    }  
}; 

function setMajor(){
	var majorName = O("majorName").value;
	var term=O("term").value;
	$.ajax({
		async:false,
     	type:"POST",
     	url:setMajor2Url,
     	dataType:"json",
     	data:{
     		majorName:majorName,
     		term:term,
     	},
     	success:function(data){
     		renderKB(data);
     		/*var len = data.length;

     	for(var i=0;i<len;i++){
     		$("#stuName").append("<option value='"+data[i].uuid+"'>"+data[i].termValue+"-"+data[i].courseName+"-"+data[i].tName+"</option>")
     	}*/
     	
     	}, 
     	error:function(err){alert("获取课表失败");},
     });  
	
}

var weekseq = {1 : '星期一', 2 : '星期二', 3 : '星期三', 4 : '星期四', 5 : '星期五'}

function renderKB(data){
	var week = new Array();
	for(var key in weekseq){
		week[weekseq[key]] = new Array();
	}
    var innerHtml = ''
	if(data != null){

        if(data[0]["message"] != "" &&  data[0]["message"] != null)
            alert(data[0]["message"]);

		for(var i = 0; i < data.length; i++){
			switch(data[i]['whichDay']){
				case weekseq[1]:
					week[weekseq[1]].push(data[i]);
					break;
				case weekseq[2]:
					week[weekseq[2]].push(data[i]);
					break;
				case weekseq[3]:
					week[weekseq[3]].push(data[i]);
					break;
				case weekseq[4]:
					week[weekseq[4]].push(data[i]);
					break;
				case weekseq[5]:
					week[weekseq[5]].push(data[i]);
					break;
			}
    	}
	}
    
	
	innerHtml = calculateKB(week)
	var kb = O('kbtable')
	kb.innerHTML = innerHtml;
}
//计算课表布局 
function calculateKB(week){
	//var kb = $('#kbtable')
	var col = new Array();
	for(var key in weekseq){
		col[weekseq[key]] = new Array();
	}
	for(var key in week){
		var flag = false;
		for(var i = 0; i < week[key].length; i++){
			var rowspan = parseInt(week[key][i]['endLesson']) - parseInt(week[key][i]['startLesson']) + 1;
			var td = '<td rowspan="' + rowspan + '" class="clickable"  \
				onclick="showoptions(' + week[key][i]['id'] + ',\'' +  week[key][i]['courseNo'] + '\' , \'' + week[key][i]['courseName'] + '\',\'' + week[key][i]['tName'] + '\',\'' + week[key][i]['classroomNo'] + '\', \''  + week[key][i]['whichDay'] + '\', ' + week[key][i]['startLesson'] + ', ' + week[key][i]['endLesson'] 
				+ ', ' + week[key][i]['startWeek'] + ', ' + week[key][i]['endWeek'] + ', \'' + week[key][i]['uuid'] + '\', event)">' + week[key][i]['courseName'] 
				+ '<br>(week ' + week[key][i]['startWeek'] + '-'+ week[key][i]['endWeek'] + ')<br>Instructor: ' + week[key][i]['tName'] + '<br>Location: ' + week[key][i]['classroomNo'] + '</td>';
			flag = false;
			for(var course = 0; course < col[key].length; course++){
				if(flag){
					break;
				}
				for(var offset = 0; offset < rowspan; offset++){
					if(col[key][course][parseInt(week[key][i]['startLesson']) + offset] == undefined){
						if(offset == rowspan - 1){
							col[key][course][parseInt(week[key][i]['startLesson'])] = td
							//合并的单元格用空格代替
							for(var placeholder = 1; placeholder < rowspan; placeholder++){
								col[key][course][parseInt(week[key][i]['startLesson']) + placeholder] = ' '
							}
							flag = true;
						}
					}
					else{
						flag = false;
						break;
					}
				}
			}
			if(flag == false){
				//保存一列，便于计数，从1开始
				var row = new Array(13);
				row[parseInt(week[key][i]['startLesson'])] = td
				//合并的单元格用空格代替
				for(var placeholder = 1; placeholder < rowspan; placeholder++){
					row[parseInt(week[key][i]['startLesson']) + placeholder] = ' '
				}
				col[key].push(row)
			}
		}
	}
	_selectteacher = "#selectteacher1";
	_selectclassroom = "#selectclassroom1";
	_selectstudent = "#selectstudent1";
	var innerHtml = '<div class="table-title">' + $("#majorNameXX").val() + ' ' + $("#term").val() + '课表</div>\
					<button style="float:left" onclick="createNewCourse();$(\'#selectteacher1,#selectassistant1, #selectclassroom1, #selectstudent1\').html(\'\');$(\'#select1\').append($(\'#teacher, #location, #student,#assistant\').clone(true));show(\'#newkb-container\');">新建课程</button>\
					<table>\
					 	<thead>\
						 	<tr>\
							 	<th>时间段</th>\
								<th>节次</th>\
								<th colspan="' + (col["星期一"].length > 1 ? col["星期一"].length : 1)  + '">星期一</th>\
								<th colspan="' + (col["星期二"].length > 1 ? col["星期二"].length : 1)  + '">星期二</th>\
								<th colspan="' + (col["星期三"].length > 1 ? col["星期三"].length : 1)  + '">星期三</th>\
								<th colspan="' + (col["星期四"].length > 1 ? col["星期四"].length : 1)  + '">星期四</th>\
								<th colspan="' + (col["星期五"].length > 1 ? col["星期五"].length : 1)  + '">星期五</th>\
							</tr>\
						</thead>\
						<tbody>'
	var end = '</tbody>\
			</table>'
	var space = 0;
	//绘制课表时间段和节次
	for(var i = 1; i < 13; i++){
		var line = ''
		switch(i){
			case 1 : line = '<tr><th rowspan="5"></br></br></br></br>上午</th><th>' + i + '</th>'
				break;
			case 6 : line = '<tr><th rowspan="4"></br></br></br>下午</th><th>' + i + '</th>'
				break;
				//把tag放在晚上单元格里
			case 10: line = '<tr><th rowspan="3"></br></br>\
			晚上</th><th>' + i + '</th>'
				break;
			default: line = '<tr><th>' + i + '</th>'
		}
		for(var key in weekseq){
			if(col[weekseq[key]].length == 0){
				line += '<td></td>'
			}
			else{
				for(var j = 0; j < col[weekseq[key]].length; j++){
					if(col[weekseq[key]][j][i] != undefined){
						line += col[weekseq[key]][j][i];
					}
					else{
						line += '<td></td>'
					}
				}
			}
		}
		line += '</tr>';
		innerHtml += line;
	}
	
	return innerHtml + end;
}

//显示编辑课表面板
function showeditkbpanel(){//_id, _courseName, _week, _startLesson, _endLesson, _startWeek, _endWeek){
	var innerHtml = '<div class="newkb pannel">\
				<div class="close-container"><a class="close" onclick="$(\'#select2\').html(\'\');hide(\'#editkbpanel\')">×</a></div>\
				<table>\
				<tr><th style="text-align:left;"><div>课程名</div></th><td style="text-align:left;"><input id="courseName2" type="hidden" value="' + g_courseNo + '">' +  g_courseName +
				'<tr><th style="text-align:left;"><div>星期</div></th><td style="text-align:left;"><select id="week2" style="width:100px">\
					<option>星期一</option>\
					<option>星期二</option>\
					<option>星期三</option>\
					<option>星期四</option>\
					<option>星期五</option>\
				</select></td></tr>\
				<tr><th style="text-align:left;"><div>节次</div></th><td style="text-align:left;">\
				第一节课 <select id="firstClass2">\
					<option>1</option><option>2</option><option>3</option>\
					<option>4</option><option>5</option><option>6</option>\
					<option>7</option><option>8</option><option>9</option>\
					<option>10</option><option>11</option><option>12</option>\
				</select>\
				最后一节课 <select id="lastClass2">\
					<option>1</option><option>2</option><option>3</option>\
					<option>4</option><option>5</option><option>6</option>\
					<option>7</option><option>8</option><option>9</option>\
					<option>10</option><option>11</option><option>12</option>\
				</select></td></tr>\
				<tr><th style="text-align:left;"><div>周次</div></th><td style="text-align:left;">\
				起始周 <select id="firstWeek2">\
					<option>1</option><option>2</option><option>3</option>\
					<option>4</option><option>5</option><option>6</option>\
					<option>7</option><option>8</option><option>9</option>\
					<option>10</option><option>11</option><option>12</option>\
					<option>13</option><option>14</option><option>15</option>\
					<option>16</option><option>17</option><option>18</option>\
				</select>\
				结束周 <select id="lastWeek2">\
					<option>1</option><option>2</option><option>3</option>\
					<option>4</option><option>5</option><option>6</option>\
					<option>7</option><option>8</option><option>9</option>\
					<option>10</option><option>11</option><option>12</option>\
					<option>13</option><option>14</option><option>15</option>\
					<option>16</option><option>17</option><option>18</option>\
				</select></td></tr>\
				<tr><th style="text-align:left;"><a style="text-decoration:underline;color:#006699" onclick="createDatatable(_select + \'.ter_1\');show(\'#select2 .teacher\');makeStringToDict(this.parentNode.parentNode.lastChild.innerHTML);checkChecked(_select + \'.ter_1\');">教师</a></th><td id="selectteacher2" ></td></tr>\
				<tr><th style="text-align:left;"><a style="text-decoration:underline;color:#006699" onclick="createDatatable(_select + \'.ass_1\'); show(\'#select2 .assistant\');makeStringToDict(this.parentNode.parentNode.lastChild.innerHTML);checkChecked(_select + \'.ass_1\');">助教</a></th><td id="selectassistant2"></td></tr>\
                <tr><th style="text-align:left;"><a style="text-decoration:underline;color:#006699" onclick="createDatatable(_select + \'.loc_1\');decorateTd(_select + \'.loc_1\');show(\'#select2 .location\')">教室</a></th><td id="selectclassroom2"></td></tr>\
				<tr><th style="text-align:left;"><a style="text-decoration:underline;color:#006699" onclick="createDatatable(_select + \'.stu_1\');show(\'#select2 .student\');makeStringToDictS(this.parentNode.parentNode.lastChild.lastChild.value,this.parentNode.parentNode.lastChild.firstChild.innerHTML);checkChecked(_select + \'.stu_1\');">学生</a></th><td><div id="selectstudent2"></div><input type="hidden" id="stu2PassportNo"></td></tr>\
				<tr><th><div></div></th><td><button style="margin-right: 10px;width:80px"id="k2" onclick="updateCourse(g_week,g_startLesson);hide(\'#editkbpanel\');$(\'#select2\').html(\'\');">确定</button></td></tr>\
				</table>\
				</div><div id="select2"></div>';
			O("editkbpanel").innerHTML = innerHtml;
			setSelectChecked("week2", g_week);
			setSelectChecked("firstClass2", g_startLesson);
			setSelectChecked("lastClass2", g_endLesson);
			setSelectChecked("firstWeek2", g_startWeek);
			setSelectChecked("lastWeek2", g_endWeek);
			$("#selectclassroom2").html(g_classroomNo);
			getKbInfo();
			$('#select2').append($('#teacher, #location, #student,#assistant').clone(true));
            load1();
			show("#editkbpanel");
}

//显示新增课时面板
function showaddkspanel(){//_id, _courseName, _week, _startLesson, _endLesson, _startWeek, _endWeek){
	addCouse();
	
	var innerHtml = '<div class="addks pannel">\
				<div class="close-container"><a class="close" onclick="$(\'#select3\').html(\'\');hide(\'#addkspanel\')">×</a></div>\
				<table>\
				<tr><th style="text-align:left;"><div>课程名</div></th><td style="text-align:left;"><input id="courseName3" type="hidden" value="' + g_courseNo + '">' +  g_courseName +
				'<tr><th style="text-align:left;"><div>星期</div></th><td style="text-align:left;"><select id="week3" style="width:100px">\
					<option>星期一</option>\
					<option>星期二</option>\
					<option>星期三</option>\
					<option>星期四</option>\
					<option>星期五</option>\
				</select></td></tr>\
				<tr><th style="text-align:left;"><div>节次</div></th><td style="text-align:left;">\
				第一节课 <select id="firstClass3">\
					<option>1</option><option>2</option><option>3</option>\
					<option>4</option><option>5</option><option>6</option>\
					<option>7</option><option>8</option><option>9</option>\
					<option>10</option><option>11</option><option>12</option>\
				</select>\
				最后一节课 <select id="lastClass3">\
					<option>1</option><option>2</option><option>3</option>\
					<option>4</option><option>5</option><option>6</option>\
					<option>7</option><option>8</option><option>9</option>\
					<option>10</option><option>11</option><option>12</option>\
				</select></td></tr>\
				<tr><th style="text-align:left;"><div>周次</div></th><td style="text-align:left;">\
				起始周 <select id="firstWeek3" disabled>\
					<option>1</option><option>2</option><option>3</option>\
					<option>4</option><option>5</option><option>6</option>\
					<option>7</option><option>8</option><option>9</option>\
					<option>10</option><option>11</option><option>12</option>\
					<option>13</option><option>14</option><option>15</option>\
					<option>16</option><option>17</option><option>18</option>\
				</select>\
				结束周 <select id="lastWeek3" disabled>\
					<option>1</option><option>2</option><option>3</option>\
					<option>4</option><option>5</option><option>6</option>\
					<option>7</option><option>8</option><option>9</option>\
					<option>10</option><option>11</option><option>12</option>\
					<option>13</option><option>14</option><option>15</option>\
					<option>16</option><option>17</option><option>18</option>\
				</select></td></tr>\
				<tr><th style="text-align:left;"><div >教师</div></th><td id="selectteacher3" ></td></tr>\
				<tr><th style="text-align:left;"><div >助教</div></th><td id="selectassistant3" ></td></tr>\
				<tr><th style="text-align:left;"><a style="text-decoration:underline;color:#006699" onclick="createDatatable(_select + \'.loc_1\');decorateTd(_select + \'.loc_1\');show(\'#select3 .location\')">教室</a></th><td id="selectclassroom3"></td></tr>\
				<tr><th style="text-align:left;"><div >学生</div></th><td><div id="selectstudent3"></div><input type="hidden" id="stu3PassportNo"></td></tr>\
				<tr><th><div></div></th><td><button style="margin-right: 10px;width:80px"id="k3" onclick="hide(\'#addkspanel\');$(\'#select3\').html(\'\');addCourse()">确定</button></td></tr>\
				</table>\
				</div><div id="select3"></div>';
			O("addkspanel").innerHTML = innerHtml;
			setSelectChecked("firstWeek3", g_startWeek);
			setSelectChecked("lastWeek3", g_endWeek);
			getKbInfo();
			$('#select3').html($('#location').clone(true));
            load1();
            show("#addkspanel");
}

var g_id, g_courseNo, g_courseName, g_tName, g_classroomNo, g_week, g_startLesson, g_endLesson, g_startWeek, g_endWeek, g_uuid, g_students;
//点击课表弹出选项
function showoptions(_id, _courseNo, _courseName, _tName, _classroomNo, _week, _startLesson, _endLesson, _startWeek, _endWeek, _uuid, e){

	g_id = _id;
	g_courseNo = _courseNo;
	g_courseName = _courseName;
	g_tName = _tName;
	g_classroomNo = _classroomNo;
	g_week = _week;
	g_startLesson = _startLesson;
	g_endLesson = _endLesson;
	g_startWeek = _startWeek;
	g_endWeek = _endWeek;
	g_uuid = _uuid;

    //editCourse();
	//showeditkbpanel();
	show("#handle-modal");
	
}

function deleteCourse(){
	$.ajax({
     	type:"POST",
     	url:delectCourseUrl,
     	dataType:"json",
     	data:{
     		majorName:$("#majorName").val(),
     		term:$("#term").val(), 		
     		courseNo:g_courseNo,
     		tName:g_tName,
     		uuid:g_uuid,
     		oldweek:g_week,
     		oldstartLesson:g_startLesson,
     		
     	},
     	success:function(data){renderKB(data)}, 
     	error:function(err){alert("删除课程出错");},
     });  
}
function getKbInfo(){
	$.ajax({
     	type:"POST",
     	url:showUpdateCourseUrl,
     	dataType:"json",
     	data:{
     		majorNo:$("#majorName").val(),
     		term:$("#term").val(), 		
     		courseNo:g_courseNo,
            uuid:g_uuid
     	},
     	success:function(data){
//     		alert("111");
//     		alert("sssss"+JSON.stringify(data));
			$("#selectstudent2").html(data[0]["stu"]);
			$("#selectteacher2").html(data[0]["tea"]);
			$("#selectassistant2").html(data[0]["assistant"]);
			$("#selectstudent3").html(data[0]["stu"]);
			$("#selectteacher3").html(data[0]["tea"]);
			$("#selectassistant3").html(data[0]["assistant"]);
			$("#stu2PassportNo").val(data[0]["passportNo"]);
			$("#stu3PassportNo").val(data[0]["passportNo"]);
			//stuPassportNO
		},
     	error:function(err){alert("获取学生信息出错");},
     });  
}

function updateCourse(oldweek,oldfirstClass2){
	//alert(oldweek);
	//alert($("#selectteacher2").html());
	//alert($("#selectassistant2").html());
	$.ajax({
     	type:"POST",
     	url:updateCourseUrl,
     	dataType:"json",
     	data:{
     		majorName:$("#majorName").val(),
     		term:$("#term").val(), 		
     		courseNo:$("#courseName2").val(),
     		uuid:g_uuid,
     		week:$("#week2").val(),
     		firstClass:$("#firstClass2").val(),
     		lastClass:$("#lastClass2").val(),
     		firstWeek:$("#firstWeek2").val(),
     		lastWeek:$("#lastWeek2").val(),
     		classrooms:$("#selectclassroom2").html(),
     		teachers:$("#selectteacher2").html(),
     		assistant:$("#selectassistant2").html(),
     		students:$("#stu2PassportNo").val(),
     		oldweek:oldweek,
     		oldfirstClass2:oldfirstClass2,
     	},

     	success:function(data){renderKB(data)}, 
     	error:function(err){alert("修改课表失败");},

     });  
}

function newCourse(){
    //alert(1);
    var majorName = O("majorName").value;
    var term = O("term").value;


    var courseName = O("courseName").value;
    var week = O("week").value;
    var firstClass = O("firstClass").value;
    var lastClass = O("lastClass").value;
    var firstWeek = O("firstWeek").value;
    var lastWeek = O("lastWeek").value;   

    var classroom = O("selectclassroom1").innerHTML;   
    var teacher = O("selectteacher1").innerHTML;
    var assistant = O("selectassistant1").innerHTML;
    var student = O("stu1PassportNo").value;  
    //alter(assistant);
    $.ajax({
        type:"POST",
        url:newCourseUrl,
        dataType:"json",
        data:{
            majorName:majorName,
            term:term,
   		
            courseName:courseName,
            week:week,
            firstClass:firstClass,
            lastClass:lastClass,
            firstWeek:firstWeek,
            lastWeek:lastWeek,
            classrooms:classroom,
            teachers:teacher,
            assistant:assistant,
            students:student
        },
        success:function(data){renderKB(data);}, 
        error:function(err){alert("新增课表出错");},
    });  
}

function addCourse(){
	$.ajax({
     	type:"POST",
     	url:addCourseUrl,
     	dataType:"json",
     	data:{
     		majorName:$("#majorName").val(),
     		term:$("#term").val(), 		
     		courseName:$("#courseName3").val(),
     		uuid:g_uuid,
     		week:$("#week3").val(),
     		firstClass:$("#firstClass3").val(),
     		lastClass:$("#lastClass3").val(),
     		firstWeek:$("#firstWeek3").val(),
     		lastWeek:$("#lastWeek3").val(),
     		classrooms:$("#selectclassroom3").html(),
     		teachers:$("#selectteacher3").html(),
     		assistant:$("#selectassistant3").html(),
     		students:$("#stu3PassportNo").val()
     	},

     	success:function(data){renderKB(data)}, 
     	error:function(err){alert("新增课时失败");},

     });  
}



/* DataTable部分
----------------------------------------------------------*/
function createDatatable(_id){
	//alert(_id);
    $(_id).DataTable({
            responsive: true,
            ordering: false,
            "bRetrieve": true,
            "bFilter": true,//过滤功能
            "aLengthMenu": [[5, 10, 50, -1], [5, 10, 50, "All"]],
            "iDisplayLength":5,
            //searching: false,
            "bLengthChange": false
    });
}
function getAllNodes(_id)
{
	return $(_id).dataTable().fnGetNodes();
}


/* 给所有的radio加上onclick属性*/
function decorateTd(_id)
{
	var allNodes = getAllNodes(_id)
	for (var tr in allNodes)
	{
		checkbox = allNodes[tr]["cells"][0]["childNodes"][0];
		checkbox["onclick"] = function(){ unCheckHiddenCheckbox(_id) }
	}
}
/* 使隐藏的页面的radio取消选中状态*/
function unCheckHiddenCheckbox(_id)
{
	var oTable = $(_id).dataTable();
	var hiddenNodes = oTable.fnGetHiddenNodes();
	var checkbox;
	for (var tr in hiddenNodes)
	{
		checkbox = hiddenNodes[tr]["cells"][0]["childNodes"][0];
		checkbox["checked"] = false
	}
}
/*start--解决新建和修改课程的重用问题--*/
var _select
var _selectteacher;
var _selectclassroom;
var _selectstudent;
var _stuPasspordNo;
var _selectteacherid;
function createNewCourse(){
    _select = "#select1 "
	_selectteacher = "#selectteacher1";
    _selectassistant = "#selectassistant1";
	_selectclassroom = "#selectclassroom1";
	_selectstudent = "#selectstudent1";
	_stuPasspordNo="#stu1PassportNo";
	
}
function editCourse(){
    _select = "#select2 "
	_selectteacher = "#selectteacher2";
    _selectassistant = "#selectassistant2";
	_selectclassroom = "#selectclassroom2";
	_selectstudent = "#selectstudent2";
	_stuPasspordNo="#stu2PassportNo";
}

function addCouse(){
	_select = "#select3 "
	_selectteacher = "#selectteacher3";
	_selectassistant = "#selectassistant3";
    _selectclassroom = "#selectclassroom3";
	_selectstudent = "#selectstudent3";
	_stuPasspordNo="#stu3PassportNo";
	}

/*end--解决新建和修改课程的重用问题--*/
/* 获取input(radio,checkbox)状态 */
function getParam(tableid, targetid)
{
	var allNodes = getAllNodes(tableid);
	var innerHtml = [];
	var ter2id = [];
	for (var tr in allNodes)
	{
		checkbox = allNodes[tr]["cells"][0]["childNodes"][0];
		//alert(checkbox["checked"]);
		if ( checkbox["checked"] == true )
		{
			if (innerHtml.length == 0){
				innerHtml.push(checkbox.value);
			}
			else{
				innerHtml.push("," + checkbox.value);
			}
		}
	}
	$(targetid).html(innerHtml);
	//alert(JSON.stringify($(targetid).html(innerHtml)));
	
}

// 改进教室弹出框重叠问题
function locTab(_id){
	$(_id).html("");
	
}

/* select全选和全部取消*/
function checkAll(obj, tableid){
    var flag = obj.checked;
    var allNodes = getAllNodes(tableid);
    for (var tr in allNodes)
	{
		checkbox = allNodes[tr]["cells"][0]["childNodes"][0];
        if(checkbox["checked"] != flag){
            checkbox["checked"] = flag;
            alterStu(checkbox);
        }
	}
}


/*选取学生功能*/
var stuDict;//存储学生-旧护照号是否上一门课
var stuPpn;//存储学生-新护照号是否上一门课
var terDict;//存储老师是否上一门课

//其实dict是用对象实现的
function makeStringToDictS(str,npp){
	//alert(str);alert(npp);
    stuDict = new Object();//每节课初始化
    var stuList = str.split(",");
    for(var seq in stuList){
        if(stuList[seq] != "" && stuList[seq] != null)
            stuDict[stuList[seq]] = 1;
    }
    stuPpn = new Object();//每节课初始化
    var stuList2 = npp.split(",");
    for(var seq in stuList2){
        if(stuList2[seq] != "" && stuList2[seq] != null)
        	stuPpn[stuList2[seq]] = 1;
    }
}//储存学生
function makeStringToDict(str){
    stuDict = new Object();//每节课初始化
    var stuList = str.split(",");
    for(var seq in stuList){
        if(stuList[seq] != "" && stuList[seq] != null)
            stuDict[stuList[seq]] = 1;
    }
}//储存教师
function alterStu(obj){
    if(stuDict[obj.value] == undefined || stuDict[obj.value] == null || stuDict[obj.value] == 0)
        stuDict[obj.value] = 1;
    else 
        stuDict[obj.value] = 0;
    var newPpn = obj.getAttribute("newPpn");
    if(stuPpn[newPpn] == undefined || stuPpn[newPpn] == null || stuPpn[newPpn] == 0)
    	stuPpn[newPpn] = 1;
    else 
    	stuPpn[newPpn] = 0;
}

function fromDictToString(targetid,stuPassportNo){
	//alert(targetid);
	//alert(stuPassportNo);
    var stuList = new String();
    for(var passportNo in stuDict){
        if(stuDict[passportNo] == 1){
            stuList += passportNo + ",";
        }
    }
    stuList = stuList.substring(0,stuList.length - 1);
    $(stuPassportNo).val(stuList);
    
    var stuList2 = new String();
    for(var passportNo2 in stuPpn){
        if(stuPpn[passportNo2] == 1){
            stuList2 += passportNo2 + ",";
        }
    }
    stuList2 = stuList2.substring(0,stuList2.length - 1);
    $(targetid).html(stuList2);//alert(stuList2);
}


function checkChecked(tableid){
    var allNodes = getAllNodes(tableid);
    for (var tr in allNodes)
	{
		checkbox = allNodes[tr]["cells"][0]["childNodes"][0];
        if(stuDict[checkbox.value] == 1)
            checkbox["checked"] = true;
	}
}

/*导出课程名单*/
function exportName(){
	var uuid = g_uuid;
	$("#stuName").val(uuid);
	//alert(uuid);
}